package com.example.projectcode.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.projectcode.mapper.KdpointsMapper;
import com.example.projectcode.mapper.SubjectMapper;
import com.example.projectcode.model.Kdpoints;
import com.example.projectcode.model.Subject;
import com.example.projectcode.service.KdpointsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Primary;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class KdpointsServiceImpl extends ServiceImpl<KdpointsMapper, Kdpoints> implements KdpointsService {

    @Autowired
    private KdpointsMapper kdpointsMapper;
    @Autowired
    private SubjectMapper subjectMapper;

    @Override
    public List<Kdpoints> selectAllKdpoints(Integer subid) {
//        QueryWrapper<Kdpoints> queryWrapper = new QueryWrapper<>();

        return kdpointsMapper.selectAllKdpointsBySubid(subid);
    }

    @Override
    public List<Kdpoints> selectKdpointsBySubId(Integer subId) {
        return baseMapper.selectList(new QueryWrapper<Kdpoints>().eq("Subid",subId));
    }

    @Override
    public int insertkdpoints(String subName, String kDcontent) {
        Kdpoints kdpoints = new Kdpoints();
        Subject subject = new Subject();
        subject = subjectMapper.selectOne(new QueryWrapper<Subject>().eq("Subname",subName));
        kdpoints.setSubid(subject.getSubid());
        kdpoints.setKDcontent(kDcontent);
        return baseMapper.insert(kdpoints);
    }

    @Override
    public int updatekdpoints(Integer kDid, String kDcontent) {

        return kdpointsMapper.updateKdpoints(kDid,kDcontent);
    }

    @Override
    public int deletekdpoints(Integer kDid) {
        return baseMapper.delete(new QueryWrapper<Kdpoints>().eq("K_Did",kDid));
    }


}
